package com.aiju.cash.ui.multiple_shops.present.presentiml;

import android.text.TextUtils;

import com.aiju.app.SimpleHttpCallback;
import com.aiju.bean.Shop;
import com.aiju.cash.core.api.ShopManagetApi;
import com.aiju.cash.ui.multiple_shops.activity.IShopManagerUiListener;
import com.aiju.cash.ui.multiple_shops.present.ipresent.IShopManagerPresent;
import com.aiju.cash.util.GsonHelper;
import com.aiju.widgit.dialog.DialogHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/12.
 */

public class ShopManagerPresent implements IShopManagerPresent {
    private IShopManagerUiListener mListener;
    private ShopManagetApi mShopManagetApi;
    private List<Shop> list=new ArrayList<>();

    public ShopManagerPresent(IShopManagerUiListener listener, DialogHelper dialogHelper) {
        mListener = listener;
        mShopManagetApi = new ShopManagetApi(dialogHelper);

    }


    @Override
    public void getShopList(int currentNum, int pageSize) {
        mShopManagetApi.setDialogHelper(null);
        mShopManagetApi.getShopList(currentNum, pageSize, new SimpleHttpCallback() {
            @Override
            protected void onDataSuccess(String data) {
                // TODO: 2017/6/13 解析数据
                List<Shop> list = GsonHelper.convertEntities(data, Shop.class);
                mListener.getShopList(list);
            }
        });
    }

    @Override
    public void getSwitchList(int currentNum, int pageSize) {
        mShopManagetApi.setDialogHelper(null);
        mShopManagetApi.getSwitchList(currentNum, pageSize, new SimpleHttpCallback() {
            @Override
            protected void onDataSuccess(String data) {
                // TODO: 2017/6/13 解析数据
                if (!TextUtils.isEmpty(data)&&!data.equals("null")){
                    List<Shop> list = GsonHelper.convertEntities(data, Shop.class);
                    mListener.getShopList(list);
                }

            }
        });
    }
}
